<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>管理员系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <%@include file="header.jsp"%>

    <%@include file="aside.jsp"%>

    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                分类管理
                <small>分类列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="${pageContext.request.contextPath}/pages/manage/main.jsp"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">分类管理</a></li>
                <li class="active">分类列表</li>
            </ol>
        </section>

        <section class="content">

            <div class="box box-primary">

                <div class="box-body">

                    <div class="table-box">

                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default" title="新建分类" onclick="location.href='${pageContext.request.contextPath}/cate/cateadd'">
                                        <i class="fa fa-file-o"></i> 新建分类</button>
                                </div>
                            </div>
                        </div>
                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <th class="sorting">ID</th>
                                <th class="sorting">分类名</th>
                                <th class="sorting">父类ID</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${not empty pageInfo.list}">
                                <c:forEach items="${pageInfo.list}" var="cate">
                                    <c:if test="${cate.cate_parent_id==0}">
                                        <tr>
                                            <td>${cate.cate_id}</td>
                                            <td>*&nbsp;${cate.cate_name}</td>
                                            <td>${cate.cate_parent_id}</td>
                                            <td class="text-center">
                                                <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/cate/catechange?cate_id=${cate.cate_id}'">编辑</button>
                                                <button type="button" class="btn bg-olive btn-xs" onclick="del(${cate.cate_id})">删除</button>
                                            </td>
                                        </tr>
                                    </c:if>
                                    <c:if test="${cate.cate_parent_id!=0}">
                                        <tr>
                                            <td>${cate.cate_id}</td>
                                            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**${cate.cate_name}</td>
                                            <td>${cate.cate_parent_id}</td>
                                            <td class="text-center">
                                                <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/cate/catechange?cate_id=${cate.cate_id}'">编辑</button>
                                                <button type="button" class="btn bg-olive btn-xs" onclick="del(${cate.cate_id})">删除</button>
                                            </td>
                                        </tr>
                                    </c:if>
                                </c:forEach>
                            </c:if>
                            </tbody>
                        </table>
                        <c:if test="${empty pageInfo.list }">
                            <div class="alert alert-warning text-center my-5 py-5 col-12  col-md-12 offset-md-6" role="alert">
                                没有任何符合条件的分类信息
                            </div>
                        </c:if>
                    </div>

                </div>
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共${pageInfo.pages}页，共${pageInfo.total}条数据。 每页${pageInfo.pageSize}条
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/cate/findAllCate?page=1&size=${pageInfo.pageSize}" aria-label="Previous" >首页</a>
                            </li>
                            <li><a href="${pageContext.request.contextPath}/cate/findAllCate?page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}">上一页</a></li>
                            <c:forEach begin="1" end="${pageInfo.pages}" var="pageNum">
                                <li><a href="${pageContext.request.contextPath}/cate/findAllCate?page=${pageNum}&size=${pageInfo.pageSize}">${pageNum}</a></li>
                            </c:forEach>

                            <li><a href="${pageContext.request.contextPath}/cate/findAllCate?page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}">下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/cate/findAllCate?page=${pageInfo.pages}&size=${pageInfo.pageSize}" aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>

    <script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/plugins/jQueryUI/jquery-ui.min.js"></script>
    <script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
    <script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
    <script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
    <script src="${pageContext.request.contextPath}/plugins/select2/select2.full.min.js"></script>
    <script>
        function setSidebarActive(tagUri) {
            var liObj = $("#" + tagUri);
            if (liObj.length > 0) {
                liObj.parent().parent().addClass("active");
                liObj.addClass("active");
            }
        }
        $(document).ready(function() {
            setSidebarActive("cate-manage");
        });

        function del(id){
            if(confirm("你确定要删除这个分类及其下属分类(包括产品)吗?")){
                location.href="${pageContext.request.contextPath}/cate/delete?id="+id;
            }
        }
    </script>
</body>

</html>